package com.jhx.video.comment

import com.jhx.common.http.ApiManager
import com.jhx.common.http.HttpRequest
import com.jhx.common.http.ResponseCallback
import com.jhx.video.model.CommentDetail
import com.jhx.video.service.VideoService

/**
 *
 * @author Jack 2018-03-29 20:48
 */
class CommentPresenterImpl : Contract.AllCommentPresenter() {

    override fun recycler() {

    }

    override fun getComment(commentType: Int, pageIndex: Int, pageSize: Int) {
        mView?.showLoading()
        val call = ApiManager.get().getApiService(VideoService::class.java).getAllComment(commentType, pageIndex, pageSize)
        HttpRequest.getRequest().autoRecycle(mView?.getContext()).start(call, object: ResponseCallback<List<CommentDetail>>() {
            override fun onSuccess(url: String?, data: List<CommentDetail>?) {
                mView?.hideLoading()
                mView?.getCommentSuccess(data)
            }

            override fun onError(url: String?, errorCode: Int, errorMsg: String?) {
                super.onError(url, errorCode, errorMsg)
                mView?.hideLoading()
            }

        })
    }

    override fun replyComment(id: String, text: String) {
        mView?.showLoading()
        val call = ApiManager.get().getApiService(VideoService::class.java).replyComment(id, text)
        HttpRequest.getRequest().autoRecycle(mView?.getContext()).start(call, object: ResponseCallback<Any>() {
            override fun onSuccess(url: String?, data: Any?) {
                mView?.hideLoading()
                mView?.replyCommentSuccess()
            }

            override fun onError(url: String?, errorCode: Int, errorMsg: String?) {
                super.onError(url, errorCode, errorMsg)
                mView?.hideLoading()
            }
        })
    }
}